import { Controller, Get, Post, Req, Res } from '@nestjs/common'
import { Request, Response } from 'express'
import { SystemService } from './servie/system.service'

@Controller('system')
export class SystemController {
  constructor(private readonly SystemService: SystemService) {}
  // 获取用户列表
  @Get('user')
  async getUserList(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.getUserList(req.query))
  }

  // 获取权限列表
  @Get('permission')
  async getRules(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.getRules(req.query.name))
  }

  // 获取角色列表
  @Get('role')
  async getRoleList(@Req() req: Request, @Res() res: Response) {
    console.log(req.query);
    res.send(await this.SystemService.getRoleList(req.query))
  }
  // 获取所以角色
  @Get('allRole')
  async getAllRole(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.getAllRole(req.query.name?req.query.name:''))
  }
  
  // 登录
  @Post('login')
  async login(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.login(req.body))
  }
  // 注册角色
  @Post('addRole')
  async addRole(@Req() req: Request, @Res() res: Response) {
    const response = await this.SystemService.addRole(req.body)
    res.send(response)
  }
  // 修改角色
  @Post('updateRole')
  async updateRole(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.updateRole(req.body))
  }
  // 删除角色
  @Post('deleteRole')
  async deleteRole(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.deleteRole(req.body.id))
  }
  @Post('register')
  async register(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.register(req.body))
  }
  // 修改用户
  @Post('updateUser')
  async updateUser(@Req() req: Request, @Res() res: Response) {
    res.send(await this.SystemService.updateUser(req.body))
  }

  @Get('addRule')
  addRule() {
    return this.SystemService.addRule()
  }

  @Post('getMenu')
  async getMenu(@Req() req: Request, @Res() res: Response) {
    const data = await this.SystemService.getMenu(req.body)
    res.send({data})
  }
}
